/*
 * $Id: memory.h,v 1.12 2006-08-31 04:21:04 bacon Exp $
 */

#ifndef _XP_BAS_MEMORY_H_
#define _XP_BAS_MEMORY_H_

#include <xp/types.h>
#include <xp/macros.h>

#include <stdlib.h> 
#define xp_malloc  malloc
#define xp_free    free
#define xp_realloc realloc
#define xp_calloc  calloc    

#ifdef __cplusplus
extern "C" {
#endif

void* xp_memcpy_i  (void* dst, const void* src, xp_size_t n);
void* xp_memmove_i (void* dst, const void* src, xp_size_t n);
void* xp_memset_i  (void* dst, int byte, xp_size_t n);
int   xp_memcmp_i  (const void* s1, const void* s2, xp_size_t n);
void* xp_memchr_i  (const void* s, int byte, xp_size_t n);
void* xp_memrchr_i (const void* s, int byte, xp_size_t n);
void* xp_memmem (
	const void* haystack, xp_size_t hsz, const void* needle, xp_size_t nsz);
xp_size_t xp_swab (void* dst, const void* src, xp_size_t n);

#ifdef __cplusplus
}
#endif

/*
#if defined(XP_USE_STOCK_FUNCTIONS)
*/
	#include <string.h>

	#define xp_memset(dst,fill,len)  memset(dst,fill,len)
	#define xp_memcpy(dst,src,len)   memcpy(dst,src,len)
	#define xp_memmove(dst,src,len)  memmove(dst,src,len)
	#define xp_memcmp(src1,src2,len) memcmp(src1,src2,len)
	#define xp_memzero(dst,len)      memset(dst,0,len)
	#define xp_memchr(s,byte,n)      memchr(s,byte,n)

/*
#else
	#define xp_memcpy   xp_memcpy_i
	#define xp_memmove  xp_memmove_i
	#define xp_memset   xp_memset_i
	#define xp_memcmp   xp_memcmp_i
	#define xp_memchr   xp_memchr_i
#endif
*/

#define xp_memrchr xp_memrchr_i

#endif
